package com.sjy.project.fym.apply.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.sjy.framework.aspectj.lang.annotation.Log;
import com.sjy.framework.aspectj.lang.enums.BusinessType;
import com.sjy.project.fym.apply.domain.FyGoods;
import com.sjy.project.fym.apply.service.IFyGoodsService;
import com.sjy.framework.web.controller.BaseController;
import com.sjy.framework.web.domain.AjaxResult;
import com.sjy.common.utils.poi.ExcelUtil;
import com.sjy.framework.web.page.TableDataInfo;

/**
 * 物资清单Controller
 * 
 * @author ljb
 * @date 2022-04-20
 */
@Controller
@RequestMapping("/fym/apply/goods")
public class FyGoodsController extends BaseController
{
    private String prefix = "fym/apply";

    @Autowired
    private IFyGoodsService fyGoodsService;

    @RequiresPermissions("fym:apply:view")
    @GetMapping()
    public String apply()
    {
        return prefix + "/apply";
    }

    /**
     * 查询物资清单列表
     */
    @RequiresPermissions("fym:apply:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FyGoods fyGoods)
    {
        startPage();
        List<FyGoods> list = fyGoodsService.selectFyGoodsList(fyGoods);
        return getDataTable(list);
    }

    /**
     * 导出物资清单列表
     */
    @RequiresPermissions("fym:apply:export")
    @Log(title = "物资清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FyGoods fyGoods)
    {
        List<FyGoods> list = fyGoodsService.selectFyGoodsList(fyGoods);
        ExcelUtil<FyGoods> util = new ExcelUtil<FyGoods>(FyGoods.class);
        return util.exportExcel(list, "物资清单数据");
    }

    /**
     * 新增物资清单
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存物资清单
     */
    @RequiresPermissions("fym:apply:add")
    @Log(title = "物资清单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FyGoods fyGoods)
    {
        return toAjax(fyGoodsService.insertFyGoods(fyGoods));
    }

    /**
     * 修改物资清单
     */
    @RequiresPermissions("fym:apply:edit")
    @GetMapping("/edit/{goodsId}")
    public String edit(@PathVariable("goodsId") Long goodsId, ModelMap mmap)
    {
        FyGoods fyGoods = fyGoodsService.selectFyGoodsByGoodsId(goodsId);
        mmap.put("fyGoods", fyGoods);
        return prefix + "/edit";
    }

    /**
     * 修改保存物资清单
     */
    @RequiresPermissions("fym:apply:edit")
    @Log(title = "物资清单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FyGoods fyGoods)
    {
        return toAjax(fyGoodsService.updateFyGoods(fyGoods));
    }

    /**
     * 删除物资清单
     */
    @RequiresPermissions("fym:apply:remove")
    @Log(title = "物资清单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fyGoodsService.deleteFyGoodsByGoodsIds(ids));
    }
}
